<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>注册</title>
    <style type="text/css">
		form {
			width: 50%;
			margin: 0 auto;
			padding: 20px;
			background-color: #f2f2f2;
			border-radius: 5px;
		}
		input[type=text], input[type=password] {
			width: 100%;
			padding: 12px 20px;
			margin: 8px 0;
			display: inline-block;
			border: 1px solid #ccc;
			border-radius: 4px;
			box-sizing: border-box;
		}
		button {
			background-color: #4CAF50;
			color: white;
			padding: 14px 20px;
			margin: 8px 0;
			border: none;
			border-radius: 4px;
			cursor: pointer;
			width: 100%;
		}
		button:hover {
			background-color: #45a049;
		}
	</style>
</head>
<body>
<form>
    <h2>注册</h2>
    <label for="username">用户名</label>
    <input type="text" id="username" name="username" placeholder="请输入用户名">
    <label for="password">密码</label>
    <input type="password" id="password" name="password" placeholder="请输入密码">
    <button type="button" id="submit-btn">注册</button>
</form>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript">
		$(document).ready(function() {
			$('#submit-btn').click(function() {
				var username = $('#username').val();
				var password = $('#password').val();

				if (username == '' || password == '') {
					alert('用户名和密码不能为空！');
					return false;
				}

				// 向后端发送注册请求，这里只是一个示例
				$.ajax({
					type: 'POST',
					url: 'http:localhost:8080/user/register', // 替换成正确的后端接口地址
					data: {'username': username, 'password': password},
					success: function(data) {
						// 注册成功，跳转到登录页面
						window.location.href = '/login.html';
					},
					error: function() {
						alert('注册失败，请重试！');
					}
				});
			});
		});
	</script>
</body>
</html>
